import HttpUtils from '../HttpUtils/HttpUtils';
// 获取当前时间戳
var timestamp = Date.parse(new Date()) / 1000;
Page({
	...HttpUtils.func,
	data: {
		user: {
			userName: getApp().globalData.userName,
			corpName: getApp().globalData.corpName,
			partyName: getApp().globalData.partyName,
			iconUrl: "",
		},
		unReadMsg: false
	},
	myInfo(event) {  //我的资料
		var pageUrl = "../myInfo/myInfo";
		wx.navigateTo({
			url: pageUrl
		})
	},
	myHistory(event) {  //历史记录
		var pageUrl = "../history/history";
		wx.navigateTo({
			url: pageUrl
		})
	},
	myFavorite(event) {  //我的收藏
		var pageUrl = "../myFavorite/myFavorite";
		wx.navigateTo({
			url: pageUrl
		})
	},
    /**
     * 综合评价
     */
    comprehensive() { 
        wx.navigateTo({
            url: '../comprehensive/comprehensive'
        })
    },
	myVersion(event) {  //版本说明
		var pageUrl = "../version/version";
		wx.navigateTo({
			url: pageUrl
		})
	},
	myCost(event) {  //费用说明
		var pageUrl = "../myCost/myCost";
		wx.navigateTo({
			url: pageUrl
		})
	},
	myHelpCenter(event) {  //帮助中心
		var pageUrl = "../helpCenter/helpCenter";
		wx.navigateTo({
			url: pageUrl
		})
	},
	message(event) {
		var pageUrl = "../message/message";
		wx.navigateTo({
			url: pageUrl
		})
	},
	onLoad() {
		var iconUrl = getApp().globalData.iconUrl;
		var userName = getApp().globalData.userName;
		var corpName = getApp().globalData.corpName;
		var partyName = getApp().globalData.partyName;
		if (null == iconUrl || undefined == iconUrl || "" == iconUrl) {
			iconUrl = "../../img/headICON.png";
		}
		this.setData({
			"user.iconUrl": iconUrl,
			"user.userName": userName,
			"user.corpName": corpName,
			"user.partyName": partyName,
		});

		this.checkUnReadMsg();
	},
	//判断是否有新的消息
	checkUnReadMsg: function() {
		var newUrl = getApp().globalData.dangjianUrl + "/member/userMsgList";
	 	var params = {};
		params["pageIndex"] = "1";
		params["pageItems"] = "2";
		params["msgType"] = "";
		params["msgTitle"] = "";
		params["read"] = "1";
		params = JSON.stringify(params);
		this.httpGet(newUrl, params, "查询是否有未读消息失败").then(
			(respData) => {
				var result = respData.data.result.code;
				if (1 == result) {
					var msgs = respData.data.msgs;
					var items = 0;
					if (null != msgs && undefined != msgs) {
						items = msgs.items;
					}
					this.setData({
						"unReadMsg": items > 0
					});
				} else {
          this.showPageMsg("alert", respData.data.result.description)
				}
			}
		);
	},
	onPullDownRefresh: function() {
		this.onLoad();
		wx.stopPullDownRefresh();
	}
});
